package com.william.jdbcplus.boot.test.util;

import com.william.jdbcplus.boot.test.entity.TenantEntity;
import com.william.jdbcplus.boot.test.entity.UserEntity;
import com.william.jdbcplus.core.dialect.ddl.DDLUtil;
import com.william.jdbcplus.core.util.JdbcUtil;

import javax.sql.DataSource;

public class DsUtil {

    public static DataSource getMysql() {
        String url = "jdbc:mysql://192.168.8.10:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "root";
        DataSource dataSource = JdbcUtil.createDataSource(url, username, password);
        return dataSource;
    }

    public static DataSource getMysql2() {
        String url = "jdbc:mysql://192.168.8.10:3306/jeecg?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "root";
        DataSource dataSource = JdbcUtil.createDataSource(url, username, password);
        return dataSource;
    }

    public static DataSource getMysql3() {
        String url = "jdbc:mysql://192.168.8.10:3306/jeecg3?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "root";
        DataSource dataSource = JdbcUtil.createDataSource(url, username, password);
        return dataSource;
    }

    public static DataSource getOracle() {
        String url = "jdbc:oracle:thin:@192.168.8.88:1521:XE";
        String username = "HIS";
        String password = "root";
        DataSource dataSource = JdbcUtil.createDataSource(url, username, password);
        return dataSource;
    }

    public static DataSource getSqlServer() {
        String url = "jdbc:sqlserver://192.168.0.98:1433;DatabaseName=his_test";
        String username = "sa";
        String password = "lis";
        DataSource dataSource = JdbcUtil.createDataSource(url, username, password);
        return dataSource;
    }

    public static void main(String[] args) {
        //指定数据源
        DataSource ds = getMysql();

        //DDLUtil.updateDatabase("com.william.jdbcplus.boot.test", ds);

        // 根据模块更新数据库
        DDLUtil.updateTable(TenantEntity.class, ds);

        DDLUtil.updateTable(UserEntity.class, ds);
    }
}
